package com.czmh.etc.onlinepubsys.controller.mingchuang;

import cn.hutool.core.codec.Base64Decoder;
import com.czmh.etc.onlinepubsys.json.mingchuang.JSONResult;
import com.czmh.etc.onlinepubsys.request.mingchuang.UploadRequest;
import com.czmh.etc.onlinepubsys.utils.mingchuang.HttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayInputStream;

@RestController
@RequestMapping("/{version}/api/mingchang/file")
@Api(tags = "文件上传【新】- 铭创")
public class FileUploadController {

    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public JSONResult upload(@RequestBody UploadRequest req) throws Exception {
        byte[] bs = Base64Decoder.decode(req.getImage());
        return HttpUtil.upload("image", new ByteArrayInputStream(bs));
    }
}
